package kr.hyunist.androidcomplete01saeildamil.ch07;

import kr.hyunist.androidcomplete01saeildamil.*;
import android.app.*;
import android.content.*;
import android.graphics.*;
import android.graphics.Shader.TileMode;
import android.os.*;
import android.view.*;

public class MirrorPaint extends Activity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		MyView mv = new MyView(this);
		setContentView(mv);

	}

	class MyView extends View {

		public MyView(Context context) {
			super(context);
		}

		@Override
		protected void onDraw(Canvas canvas) {
			Paint pnt = new Paint();
			canvas.drawColor(Color.BLACK);

			Bitmap car = BitmapFactory.decodeResource(getContext()
					.getResources(), R.drawable.koala);

			int width = car.getWidth();
			int height = car.getHeight();

			Matrix matrix = new Matrix();
			matrix.preScale(1, -1f);
			Bitmap mirror = Bitmap.createBitmap(car, 0, 0, width, height,
					matrix, false);

			canvas.drawBitmap(car, 0, 0, null);
			ComposeShader comp = new ComposeShader(new BitmapShader(mirror,
					TileMode.REPEAT, TileMode.REPEAT), new LinearGradient(0,
					height, 0, height + height, Color.TRANSPARENT, Color.BLACK,
					TileMode.REPEAT), new PorterDuffXfermode(
					PorterDuff.Mode.DARKEN));
			pnt.setShader(comp);
			canvas.drawRect(0, height, width, height + height, pnt);
		}

	}
}
